var events = require('events');
var eventEmitter = new events.EventEmitter();

/*var eventEmitter = require('./4.event.mock')*/

/*var eventHandle = function(){
    console.log('event is emitted');
}

eventEmitter.on('event1',eventHandle);//事件注册

eventEmitter.emit('event1'); //事件触发*/


/**
 *  模拟链接数据库
 *     connect
 *     data
 *     recieve
 *     close
 *
 *    注册： 把事件相关内容注册到一个数组中
 *    使用： 轮询这个集合，触发响应内容
 * **/


eventEmitter.on('connect',function () {
    console.log("db is connected");
    eventEmitter.emit('data');
})


eventEmitter.on('data',function () {
    console.log("dating....");
})

eventEmitter.on('recieve',function () {
    console.log("data is recieving....");
})

eventEmitter.on('close',function (flag) {
    if(flag)
    {
        console.log("db is closed" + flag);
    }else{
        console.log("db is closed");
    }

})

eventEmitter.emit('connect');
eventEmitter.emit('close',true);